﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicChart.Data;

namespace Sinochem.TMS.SalesChartService
{
    public class SalesBuilder : IChartBuilder
    {
        public ChartPackage Build(DateRange dateRange, string parameterString)
        {
            ChartPackage package = new ChartPackage();
            package.Caption = "销售分析";
            package.CellWidth = 0;
            package.CellHeight = 300;

            if (dateRange == null || dateRange.Mode == "y")
            {
                package.DateRange = new DateRange();
                package.DateRange.Mode = "y";
                package.DateRange.NextMode = "m";
                package.DateRange.BeginDate = DateTime.Now.AddYears(-5);
                package.DateRange.CurrentDate = DateTime.Now;
                package.DateRange.EndDate = DateTime.Now.AddYears(5);
                package.DateRange.IsVisible = true;
            }
            else
            {
                package.DateRange = new DateRange();
                package.DateRange.Mode = "m";
                package.DateRange.NextMode = string.Empty;
                package.DateRange.BeginDate = new DateTime(dateRange.CurrentDate.Year, 1, dateRange.CurrentDate.Day);
                package.DateRange.CurrentDate = dateRange.CurrentDate;
                package.DateRange.EndDate = new DateTime(dateRange.CurrentDate.Year, 12, dateRange.CurrentDate.Day);
                package.DateRange.IsVisible = true;
            }

            package.ChartDefinitions.Add(new ChartDefinition
            {
                Row = 0,
                Col = 0,
                RowSpan = 2,
                ColSpan = 2,
                IsPackage = false,
                Module = "sales-customer",
                ParameterString = parameterString,
            });

            package.ChartDefinitions.Add(new ChartDefinition
            {
                Row = 0,
                Col = 2,
                RowSpan = 1,
                ColSpan = 1,
                IsPackage = false,
                Module = "sales-product",
                ParameterString = parameterString,
            });

            package.ChartDefinitions.Add(new ChartDefinition
            {
                Row = 1,
                Col = 2,
                RowSpan = 1,
                ColSpan = 1,
                IsPackage = false,
                Module = "sales-department",
                ParameterString = parameterString,
            });

            package.ChartDefinitions.Add(new ChartDefinition
            {
                Row = 2,
                Col = 0,
                RowSpan = 1,
                ColSpan = 2,
                IsPackage = false,
                Module = "sales-person",
                ParameterString = parameterString,
            });

            package.ChartDefinitions.Add(new ChartDefinition
            {
                Row = 2,
                Col = 2,
                RowSpan = 1,
                ColSpan = 1,
                IsPackage = false,
                Module = "sales-contract",
                ParameterString = parameterString,
            });

            return package;
        }
    }
}
